/**
 * @author xiaobyu
 * @created Jun 16, 2016
 * 
 */
package mdt.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.concurrent.atomic.AtomicLong;

public class MDTModel implements IMDTModel {

	private static final long serialVersionUID = 1L;

	private static AtomicLong seeds = new AtomicLong(0);

	private long oid = seeds.getAndIncrement();

	protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

	@Override
	public long getOID() {
		return oid;
	}

	public void addPropertyChangeListener(PropertyChangeListener l) {
		changeSupport.addPropertyChangeListener(l);
	}

	public void removePropertyChangeListener(PropertyChangeListener l) {
		changeSupport.removePropertyChangeListener(l);
	}

	public void firePropertyChange(String pName, Object oldV, Object newV) {
		changeSupport.firePropertyChange(pName, oldV, newV);
	}

	public void firePropertyChange(String pName, boolean oldV, boolean newV) {
		changeSupport.firePropertyChange(pName, oldV, newV);
	}

	public void firePropertyChange(String pName, int oldV, int newV) {
		changeSupport.firePropertyChange(pName, oldV, newV);
	}

	public void firePropertyChange(String pName, String oldV, String newV) {
		changeSupport.firePropertyChange(pName, oldV, newV);
	}

	public Object clone() { //TODO also problematic...
		try {
			MDTModel cloned = (MDTModel)super.clone();
			cloned.oid = seeds.getAndIncrement();
			cloned.changeSupport = new PropertyChangeSupport(cloned);
			return cloned;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return null;
	}

}
